package Usermanagement

import (
	"database/sql"
	"fmt"
	"log"
)

func AddUser(db *sql.DB, m *Mainfase) error {
	query := `INSERT INTO Manager_users (id,name, gender, age, email,password) VALUES ($1, $2, $3, $4,$5,$6)`
	_, err := db.Exec(query, m.Id, m.Name, m.Gender, m.Age, m.Email, m.Password)
	if err != nil {
		return err
	}
	return nil
}

func Adduser_test() {
	var select_number_bool string
	db, err := ConnectDB()
	if err != nil {
		log.Fatal("数据库连接失败:", err)
	}
	defer db.Close()
	for {
		fmt.Println("---------------添加客户开始-----------------------")
		returnMonologue := Monologue()
		err := AddUser(db, returnMonologue)
		if err != nil {
			fmt.Println("添加用户失败:", err)
		} else {
			fmt.Println("用户添加成功！")
		}

		fmt.Print("是否返回上一层[y/n]：")
		fmt.Scan(&select_number_bool)
		if select_number_bool == "y" {
			break
		} else if select_number_bool == "n" {
			continue
		} else {
			fmt.Println("请重新输入你的选择{y/n}")
		}
	}
}
